SONARJAVA-5160 S1144 Handle arrays in @MethodSource#5638
Conversation
Agentic Analysis: Early ResultsAgentic Analysis and Context Augmentation are available on your project. Here are some issues that could have been prevented. Follow the links to learn how to put them into action. 6 issue(s) found across 1 file(s):
Analyzed by SonarQube Agentic Analysis in 6.3 s |
54f2553 to
7ece85f
Compare
2a40bd9 to
ec6916d
Compare
ec6916d to
5d1aee6
Compare
|
|
||
| private void removeMethodNames(NewArrayTree newArrayTree) { | ||
| for (ExpressionTree initializer : newArrayTree.initializers()) { | ||
| if (initializer.is(Tree.Kind.STRING_LITERAL)) { |
There was a problem hiding this comment.
The condition should always be true (or the code doesn't compile)
There was a problem hiding this comment.
The initializer must be known at compile time, but does not have to be a literal. For example, the following is fine:
private static final String PROVIDE_DATA_ARRAY = "provideDataArray";
@ParameterizedTest
@MethodSource(value = {PROVIDE_DATA_ARRAY, PROVIDE_DATA_ARRAY + "2"})
void testAddArray(int num) {}
This is, however, a corner case, and I don't think supporting it is a good use of time.
rombirli
left a comment
There was a problem hiding this comment.
LGTM, minor suggestions
|
Code Review ✅ Approved 4 resolved / 4 findingsUpdates ✅ 4 resolved✅ Quality: Unused method overload: removeMethodName(String)
✅ Quality: Javadoc typo:
|
| Auto-apply | Compact |
|
|
Was this helpful? React with 👍 / 👎 | Gitar




Summary by Gitar
UnusedPrivateMethodCheckto correctly identify methods referenced as arrays in@MethodSourceannotations.NEW_ARRAYtrees within annotation arguments to extract and filter method names.UnusedPrivateMethodSampleTest.javato verify false-positive prevention with array-based@MethodSourceconfigurations.UnusedPrivateMethodCheckTestto validate the check against the sample file.This will update automatically on new commits.